package com.hunt.controller;


import com.alibaba.fastjson.JSON;
import com.hunt.dao.RehabilitationMapper;
import com.hunt.model.app.Rehabilitation;
import com.hunt.service.RehabilitationService;
import com.hunt.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;






import java.util.ArrayList;
import java.util.List;

@Api("外部输入复权信息")
@Controller
@RequestMapping("/outside/rehabilitation")
public class RehabilitationController {

   @Autowired
   private RehabilitationMapper rehabilitationMapper;

    @ApiOperation(value = "输入复权数据", httpMethod = "POST", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "insertdata", method = RequestMethod.POST)
    public Result insertdata(@RequestParam(value = "data", defaultValue = "0") String data) {
        List<Rehabilitation> list= JSON.parseArray(data, Rehabilitation.class);
        List<Rehabilitation> listfix= new ArrayList<>();
        for(Rehabilitation r:list){
            if(rehabilitationMapper.getlastnum(r.getCode(),r.getDateTime())==0){
                listfix.add(r);
            }
        }
        rehabilitationMapper.insertrehabilitation(listfix);
        return  Result.success();
    }
    @ApiOperation(value = "获取复权数据", httpMethod = "POST", produces = "application/json", response = Result.class)
    @ResponseBody
    @RequestMapping(value = "getdata", method = RequestMethod.POST)
    public Result getdata(@RequestParam(value = "code") String code) {
        List<Rehabilitation> list= rehabilitationMapper.getrehabilitation(code);
        return  Result.success(list);
    }
}
